Crate open

source ·
Expand description

Use this library to open a path or URL using the program configured on the system in a non-blocking fashion.

Usage

Open the given URL in the default web browser, without blocking.

open::that("http://rust-lang.org").unwrap();

Alternatively, specify the program to be used to open the path or URL.

open::with("http://rust-lang.org", "firefox").unwrap();

Notes

Nonblocking operation

The functions provided are nonblocking as it will return even though the launched child process is still running. Note that depending on the operating system, spawning launch helpers, which this library does under the hood, might still take 100’s of milliseconds.

Error handling

As an operating system program is used, the open operation can fail. Therefore, you are advised to check the result and behave accordingly, e.g. by letting the user know that the open operation failed.

let path = "http://rust-lang.org";

match open::that(path) {
    Ok(()) => println!("Opened '{}' successfully.", path),
    Err(err) => eprintln!("An error occurred when opening '{}': {}", path, err),
}

Functions

Open path with the default application without blocking.
Open path with the default application in a new thread.
Open path with the given application.
Open path with the given application in a new thread, which is useful if the program ends up to be blocking. Otherwise, prefer with() for straightforward error handling.